var o = getApp();

Page({
    data: {
        showBox: "main",
        shopName: "",
        userName: "",
        signName: "",
        imageUrl1: "",
        imageUrl2: "",
        bannerImg: "",
        bgImg: "",
        action: "upload.uploadPic",
        shopModle: {
            shop_background: "",
            signature: ""
        },
        showInfo: !0,
        changeType: "",
        shop_id: "",
        shoplang: ""
    },
    onLoad: function(o) {
        o.shop_id && this.setData({
            shop_id: o.shop_id
        }), this.getJson();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getJson: function() {
        var a = this, t = o.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.set-shop");
        o._getNetWork({
            url: t,
            success: function(o) {
                var t = o.data;
                if (1 == t.result) {
                    var e = t.data.micro_shop;
                    a.setData({
                        shopName: e.shop_name,
                        userName: e.has_one_member.nickname,
                        signName: e.signature,
                        imageUrl1: e.shop_avatar,
                        imageUrl2: e.has_one_member.avatar,
                        postUrl: e.api ? e.api : "",
                        bannerImg: t.data.select_goods_thumb,
                        bgImg: 0 == e.shop_background ? "" : e.shop_background,
                        "shopModle.shop_background": t.data.micro_shop.shop_background,
                        "shopModle.signature": t.data.micro_shop.signature
                    }), t.data.lang && (a.setData({
                        shoplang: t.data.lang
                    }), wx.setNavigationBarTitle({
                        title: a.data.shoplang + "设置"
                    }));
                }
            },
            fail: function(o) {
                console.log(o);
            }
        });
    },
    changeActive: function(a) {
        var t = a.currentTarget.dataset.bol;
        if (1 == a.currentTarget.dataset.num) {
            var e = o.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.set-shop.edit");
            if (o._isTextEmpty(this.data.shopModle.shop_background)) return void wx.showToast({
                icon: "none",
                title: "微店背景不能为空",
                duration: 1500
            });
            if (o._isTextEmpty(this.data.shopModle.signature)) return void wx.showToast({
                icon: "none",
                title: "微店个性签名不能为空",
                duration: 1500
            });
            e += "&shop_set=" + JSON.stringify(this.data.shopModle), o._getNetWork({
                url: e,
                success: function(o) {
                    var a = o.data;
                    1 == a.result ? wx.navigateBack({
                        delta: 1
                    }) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 2500
                    });
                },
                fail: function(o) {
                    console.log(o);
                }
            });
        } else this.setData({
            showInfo: t
        });
    },
    manageShop: function() {
        wx.navigateTo({
            url: "/packageC/microshop/manage_shop/manage_shop"
        });
    },
    changeShowBox: function(o) {
        var a = o.currentTarget.dataset.text;
        this.setData({
            changeType: a
        }), "店招背景" == a ? this.setData({
            showBox: "upLoadBox"
        }) : "个性签名" == a || "微店名称" == a || "店主昵称" == a ? this.setData({
            showBox: "inputBox"
        }) : this.setData({
            showBox: "main"
        });
    },
    onRead: function() {
        var a = this, t = o.getNetAddresss(this.data.action);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(o) {
                var e = o.tempFilePaths;
                console.log(e[0]), wx.compressImage({
                    src: e[0],
                    quality: 60,
                    success: function(o) {
                        var e = o.tempFilePath;
                        wx.uploadFile({
                            url: t,
                            filePath: e,
                            name: "file",
                            success: function(o) {
                                var t = JSON.parse(o.data);
                                1 == t.result ? a.setData({
                                    bgImg: t.data.img_url,
                                    "shopModle.shop_background": t.data.img_url
                                }) : wx.showToast({
                                    icon: "none",
                                    title: t.msg,
                                    duration: 1500
                                });
                            }
                        });
                    },
                    fail: function(o) {},
                    complete: function(o) {}
                });
            }
        });
    },
    signatureinp: function(o) {
        var a = o.detail.value;
        this.setData({
            "shopModle.signature": a
        });
    },
    gomicroshopaddcategory: function() {
        wx.navigateTo({
            url: "/packageC/microshop/micro_shop_add_category/micro_shop_add_category?shop_id=" + this.data.shop_id
        });
    },
    closePopInput: function() {
        this.setData({
            showBox: "main",
            changeVal: ""
        });
    }
});